﻿var Bom = {};
//设置
Bom.settings = {
    TaskId: com.get.Id,
    TaskCode: "",
    Action: null,
    editRow: undefined,
    ColumnsParam: [],
    currentTr: null,
    MPState: "",
    MPType: "",
    SubmitType: "",
    EquipId: 0,
    CopySwitch: "1",//0代表复制开关打开，1代表关闭
    Ids: "",
    ColumnState: "1"
};
var searchAction = "bomSearch";
Bom.init = function () {
    $("#TaskId").val(Bom.settings.TaskId);
    //新增涂装方案表格初始化
    $('#divAddTuZhuang').dialog({
        title: '添加涂装方案',
        width: 800,
        height: 250,
        modal: true,
        buttons: [{
            text: '保存',
            handler: function () {
                //console.log($('#myForm'));
                var myForm = com.serializeObj('myForm');

                //console.log(JSON.stringify(myForm));
                //console.log($('#myForm').serialize());

                com.ajax({
                    url: '/Logic/TM/OrgDataAjax.aspx?method=SetValue',
                    data: $.extend(myForm, { Ids: Bom.settings.Ids }),
                    success: function (data) {
                        com.message(data.state, data.msg);

                        //$("#myForm").form("reset");
                        $("#divAddTuZhuang").dialog("close");
                        $("#tbList").datagrid("clearSelections");
                        $("#tbList").datagrid("reload");

                        $("#myForm").form("reset");
                        $('#SunHao1').numberbox("setValue", '1.65');
                        $('#SunHao2').numberbox("setValue", '1.65');
                        $('#SunHao3').numberbox("setValue", '1.65');
                        Bom.settings.Ids = "";
                    }
                })

            }
        }, {
            text: '关闭',
            handler: function () {
                $("#myForm").form("reset");
                $('#SunHao1').numberbox("setValue", '1.65');
                $('#SunHao2').numberbox("setValue", '1.65');
                $('#SunHao3').numberbox("setValue", '1.65');
                Bom.settings.Ids = "";
                $('#divAddTuZhuang').dialog('close');
            }
        }],
    });
    $('#divAddTuZhuang').dialog('close');


    //加载任务信息
    com.ajax({
        url: "/Logic/TM/TaskManagerAjax.aspx?method=GetTaskInfoByPrimaryId&TaskId=" + Bom.settings.TaskId, success: function (data) {
            $("#lblTaskCode").html(data.TaskCode);
            $("#lblProjName").html(data.ProjName);
            $("#lblEngName").html(data.EngName);
            $("#lblNum").html(data.TaskNum);
            $("#lblEquipName").html(data.EquipName);
            $("#lblEquipModel").html(data.EquipModel);
            $("#lblTaskWeight").html(data.BomWeight);
            $("#lblTaskArea").html(data.BomArea);
            $("#hidEquipId").val(data.EquipId);
            $("#lblTaskState").html(com.getArrayText(StaticCombo.TaskState, data.State));
            if (data.State == "2" || data.State == "6") {
                $("#btnSubmitPlan").linkbutton("disable");
            }
            Bom.settings.TaskCode = data.TaskCode;
            Bom.settings.EquipId = data.EquipId;
            Bom.settings.EquipModel = data.EquipModel;
        }
    });

    var height = $("#divTotal").height();

    var master = $("#master").height();
    var content = parseFloat(height) - parseFloat(master) - 45;
    $("#tbList").css("height", content);


    var isCtrlDown = false;
    var rowsIndexes = new Array();
    $(document).keydown(function (event) {
        if (event.keyCode == 16) {
            isCtrlDown = true;
        }
    });
    $(document).keyup(function (event) {
        if (event.keyCode == 16) {
            isCtrlDown = false;
            rowsIndexes.length = 0;
        }
        else if (event.keyCode == 17) {
            rowsIndexes.length = 0;
            $("#tbList").datagrid("clearSelections");
        }
    });
    //加载原始数据列表
    $("#tbList").datagrid({
        url: '/Logic/TM/OrgDataAjax.aspx?method=GetOrgDataByTaskId',
        loadMsg: '数据加载中请稍后……',
        //fitColumns: true,
        pagination: true,

        remoteSort: false,
        rownumbers: true,
        idField: "ID",
        singleSelect: false,
        autoRowHeight: false,
        nowrap: true,
        pageSize: 20,
        pageList: [20, 50, 100, 500],
        queryParams: com.serializeSearchArray("form1"),

        frozenColumns: [[
            { field: 'ck', checkbox: true, width: 30 },

        {
            field: 'MpState', title: 'C ', align: "center", width: 20, formatter: function (value, row, Index) {

                return com.getArrayText(StaticCombo.OrgAuditState, row.MpReviewState);
            }, styler: function (value, row, index) {
                if (row.MpState == "1") {
                    return 'background-color:green';
                }
                else if (row.MpState == "2") {
                    return 'background-color:red';
                }
                else if (row.MpState == "3") {
                    return 'background-color:gray';
                } else if (row.MpState == "4") {
                    return 'background-color:#49C4FA';
                }
            }
        },
        {
            field: 'OsState', title: 'W ', align: "center", width: 20, formatter: function (value, row, Index) {

                return com.getArrayText(StaticCombo.OrgAuditState, row.OsReviewState);
            }, styler: function (value, row, index) {
                if (row.OsState == "1") {
                    return 'background-color:green';
                }
                else if (row.OsState == "2") {
                    return 'background-color:red';
                }
                else if (row.OsState == "3") {
                    return 'background-color:gray';
                } else if (row.OsState == "4") {
                    return 'background-color:#49C4FA';
                }
            }
        },
        //{
        //    field: 'MsState', title: 'B', align: "center", width: 20, formatter: function (value, row, Index) {

        //        return com.getArrayText(StaticCombo.OrgAuditState, row.MsReviewState);
        //    }, styler: function (value, row, index) {
        //        if (row.MsState == "1") {
        //            return 'background-color:green';
        //        }
        //        else if (row.MsState == "2") {
        //            return 'background-color:red';
        //        }
        //        else if (row.MsState == "3") {
        //            return 'background-color:gray';
        //        } else if (row.MsState == "4") {
        //            return 'background-color:#49C4FA';
        //        }
        //    }
        //},
         {
             field: 'ZkAssState', title: 'Z ', align: "center", width: 20, formatter: function (value, row, index) { return row.ZkAssState == "2" ? "Y" : "" }, styler: function (value, row, index) {
                 if (row.ZkAssState == "1" || row.ZkAssState == "2") {
                     return 'background-color:green';
                 } else if (row.ZkClassId != 0 && typeof (row.ZkClassId) != undefined && row.ZkClassId != null) {
                     return 'background-color:#F3ED77';
                 }
             }
         },
                  {
                      field: 'FfAssState', title: 'F', align: "center", width: 20, formatter: function (value, row, index) { return row.FfAssState == "2" ? "Y" : "" }, styler: function (value, row, index) {
                          if (row.FfAssState == "1" || row.FfAssState == "2") {
                              return 'background-color:green';
                          } else if (row.FangFuId != 0 && typeof (row.FangFuId) != undefined && row.FangFuId != null) {
                              return 'background-color:#F3ED77';
                          }
                      }
                  },

                 {
                     field: 'MapAssState', title: 'T ', align: "center", width: 20, formatter: function (value, row, index) { return row.MapAssState == "2" ? "Y" : "" }, styler: function (value, row, index) {
                         if (row.MapAssState == "1" || row.MapAssState == "2") {
                             return 'background-color:green';
                         } else if (row.ClassId != 0 && typeof (row.ClassId) != undefined && row.ClassId != null) {
                             return 'background-color:#F3ED77';
                         }
                     }
                 }, {
                     field: 'MkState', title: 'M ', align: "center", width: 20, formatter: function (value, row, Index) {

                         return com.getArrayText(StaticCombo.OrgAuditState, row.MkReviewState);
                     }, styler: function (value, row, index) {
                         if (row.MkState == "1") {
                             return 'background-color:green';
                         }
                         else if (row.MkState == "2") {
                             return 'background-color:red';
                         }
                         else if (row.MkState == "3") {
                             return 'background-color:gray';
                         } else if (row.MkState == "4") {
                             return 'background-color:#49C4FA';
                         }
                     }
                 },
                  {
                      field: 'IsReplace', title: '代', align: "center", width: 20, formatter: function (value, row, Index) {

                          if (value == "1") {
                              return '<a href="#" title="规格：' + row.RePlaceGuige + '，材质：' + row.RePlaceCaizhi + '" class="note" style="text-decoration:none;color:red">代</a>';

                          }
                          else {
                              return "";
                          }
                      }, styler: function (value, row, index) {
                          if (value == "1") {
                              return 'cursor:pointer';
                          }

                      }
                  },
          { field: 'MsXuhao', title: '明细序号', align: "center", width: 70 },
         {
             field: 'Xuhao', title: '总序', align: "center", sortable: true, width: 70, sorter: Bom.DIYSort
         },
         //{ field: 'Zongxu', title: '总序', align: "center", width: 70 },

         { field: 'Map', title: '图号', align: "center", width: 70 },
         { field: 'ComponentIDNum', title: '构件标识号', align: "center", width: 70 },
         { field: 'ComponentNum', title: '零件号', align: "center", width: 60 },
         { field: 'EquipSubName', title: '设备子项名称', align: "center", width: 100 },
         { field: 'MaterialName', title: '零部件名称', align: "center", width: 120 },

        ]],
        columns: [[

            { field: 'SingleNum', title: '数量 ', align: "center", width: 40 },
            { field: 'MaterialGuige', title: '截面型材', align: "center", width: 100 },
         { field: 'MaterialCaizhi', title: '材质 ', align: "center", width: 100 },

          { field: 'PackNum', title: '包号', align: "center", width: 60 },
          { field: 'BoxNum', title: '箱号', align: "center", width: 250 },
          { field: 'Kong', title: '孔', align: "center", width: 100 },
            { field: 'PaintProgram', title: '涂装方案', align: "center", width: 200 },
         { field: 'Length', title: '长度(mm)', align: "center", width: 60 },
         { field: 'UnitWeight', title: '单重(kg)', align: "center", width: 70 },
         { field: 'TotalWeight', title: '总重(kg)', align: "center", width: 70 },
         { field: 'MaUnitWeight', title: '单重(毛)(kg)', align: "center", width: 70 },
         { field: 'MaTotalWeight', title: '总重(毛)(kg)', align: "center", width: 70 },
         //{ field: 'MaterialGB', title: '国标', align: "center", width: 120 },
         //{ field: 'HidGuige', title: '材料规格', align: "center", width: 100 },
         { field: 'MaterialCode', title: '物料编码', align: "center", width: 100 },
         { field: 'Area', title: '单面积(m²)', align: "center", width: 60 },
         { field: 'TotalArea', title: '总面积(m²)', align: "center", width: 80 },
         { field: 'PaintArea', title: '喷漆面积(m²)', align: "center", width: 80 },
         { field: 'BottomPaint', title: '底层油漆', align: "center", width: 100 },
         { field: 'MiddlePaint', title: '中层油漆', align: "center", width: 100 },
         { field: 'SurfacePaint', title: '表面油漆', align: "center", width: 100 },
         {
             field: 'SingleOrDouble', title: '是否单面喷漆', align: "center", width: 90, formatter: function (value, row, Index) {

                 if (value == "0") {
                     return "双面喷漆";
                 } else if (value == "1") {
                     return "单面喷漆";
                 } else if (value = "2") {
                     return "不喷漆";
                 }
             }
         },
          {
              field: 'AlterState', title: '变更状态', align: "center", width: 80, formatter: function (value, row, Index) {
                  //alert(value);
                  if (value == "1") {

                      return "可变更";
                  } else {
                      return "不可变更";
                  }
              }
          },
         { field: 'TotalLength', title: '外观长度(mm)', align: "center", width: 80 },
         { field: 'Width', title: '外观宽度(mm) ', align: "center", width: 80 },
         { field: 'Height', title: '外观高度(mm) ', align: "center", width: 80 },
         { field: 'MaterialTheroWeight', title: '理论重量', align: "center", width: 60 },
         { field: 'ClassName', title: '制作班组', align: "center", width: 60 },
         { field: 'FangFuName', title: '防腐班组', align: "center", width: 60 },
         { field: 'ZkClassName', title: '制孔班组', align: "center", width: 60 },

         { field: 'Bolt', title: '螺栓', align: "center", width: 100 },

         { field: 'Note', title: '备注', align: "center", width: 350 },
         { field: 'BatchNum1', title: '批次', align: "center", width: 70 },
         { field: 'PlanArea', title: '计划面域', align: "center", width: 70 },
         { field: 'MaState', title: '毛胚状态 ', align: "center", width: 60 },

         { field: 'Ku', title: "K", align: "center", width: 50 },
         {
             field: 'Process', title: '工艺流程 ', align: "center", width: 70, formatter: function (value, row, Index) {

                 return com.getArrayText(StaticCombo.Process, value);
             }
         },
         { field: 'IsFixedSize', title: '是否定尺 ', align: "center", width: 60 },
         { field: 'SelfWeight', title: '部件自重 ', align: "center", width: 60 },
         { field: 'IsSubmitMs', title: '制作明细 ', align: "center", width: 60 },
         { field: 'IsSubmitMp', title: '材料计划 ', align: "center", width: 60 },
         {
             field: 'BlankType', title: '下料类别 ', align: "center", width: 70, formatter: function (value, row, Index) {

                 return com.getArrayText(StaticCombo.BlankType, value);
             }
         },
           { field: 'FillDate', title: '操作时间 ', align: "center", width: 140, sortable: true },
         { field: 'RePlaceGuige', title: '代用规格', align: "center", width: 100 },
         { field: 'RePlaceCaizhi', title: '代用材质', align: "center", width: 100 },
         //{ field: 'OrgMaterialName', title: '原始物料名称', align: "center", width: 80 }
        ]],
        onClickRow: function (index, row) {
            rowsIndexes.push(index);
            if (isCtrlDown == true) {
                if (rowsIndexes.length > 1) {
                    rowsIndexes.sort(function (a, b) { return a - b; });
                    var min_index = rowsIndexes[0];
                    var max_index = rowsIndexes[rowsIndexes.length - 1];
                    for (var i = min_index; i <= max_index; i++) {
                        $(this).datagrid('selectRow', i);
                    }
                }
            }

        },
        rowStyler: function (index, row) {
            if (row.AlterState == "1") {
                return 'background-color:yellow;color:blue;font-weight:bold;';
            }
        }

        //onCheck: function (index, row) {
        //    rowsIndexes.push(index);
        //    if (isCtrlDown == true) {
        //        if (rowsIndexes.length > 1) {
        //            rowsIndexes.sort(function (a, b) { return a - b; });
        //            var min_index = rowsIndexes[0];
        //            var max_index = rowsIndexes[rowsIndexes.length - 1];
        //            for (var i = min_index; i <= max_index; i++) {
        //                $(this).datagrid('selectRow', i);
        //            }
        //        }
        //    }
        //},
    });


    //加载操作列的显示隐藏数据
    com.ajax({
        url: '/Logic/TM/OrgDataAjax.aspx?method=GetPersonColumn', success: function (data) {
            Bom.settings.ColumnsParam = data;
            $("#divOperate").dialog("close");
        }
    });



    //初始化高级筛选窗口
    //初始化列显示隐藏界面
    $('#divHighSearch').dialog({
        title: '高级筛选',
        width: 560,
        height: 320,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: true,
        href: '/UI/BD/HighSearchWindow.aspx?action=bomSearch',
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                $.extend(o, com.serializeSearchArray("form1"));
                $.extend(o, com.getHighSearchList());
                $("#tbList").datagrid("load", o);
                $("#divHighSearch").dialog("close");
            }
        }, { text: "取消", handler: function () { $("#divHighSearch").dialog("close"); } }]
    });
    $("#divHighSearch").dialog("close");





    //初始化列显示隐藏界面
    $('#divColumn').dialog({
        title: '编辑窗口',
        width: 630,
        height: 400,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true
    });
    $("#divColumn").dialog("close");

    //初始化调整序号界面
    $('#divAdjustXuhao').dialog({
        title: '调整明细序号',
        width: 320,
        height: 120,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var oldXuHao = $("#txtOldXuHao").val();
                var newXuHao = $("#txtNewXuHao").val();
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=AdjustXuHao", data: { oldXuHao: oldXuHao, newXuHao: newXuHao, taskId: com.get.Id }, success: function (data) {
                        com.message(data.state, data.msg);
                        if (data.state == "success") {
                            $("#divAdjustXuhao").dialog("close");
                            $("#tbList").datagrid("reload");
                            $("#txtOldXuHao").val("");
                            $("#txtNewXuHao").val("");
                        }
                    }
                });
            }
        }, { text: "取消", handler: function () { $("#divAdjustXuhao").dialog("close"); } }]
    });
    $("#divAdjustXuhao").dialog("close");

    //初始化增加前缀序号界面
    $('#divMap').dialog({
        title: '前缀图号',
        width: 180,
        height: 120,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var rows = $("#tbList").datagrid("getSelections");
                var txtFrontMap = $("#frontMap").val();
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=AddFrontMap", data: { FrontMap: txtFrontMap, orgData: JSON.stringify(rows), CopySwitch: Bom.settings.CopySwitch }, success: function (data) {
                        var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };

                        $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                        $("#tbList").datagrid("unselectAll");
                        com.message(data.state, data.msg, function () {
                            $("#divMap").dialog("close");
                        });

                    }
                });
            }
        }, { text: "取消", handler: function () { $("#divMap").dialog("close"); } }]
    });
    $("#divMap").dialog("close");


    //单行复制
    $('#divCopyData').dialog({
        title: '复制数据',
        width: 300,
        height: 200,
        collapsible: true,
        minimizable: false,
        closable: true,
        cache: false,
        modal: true,
        buttons: [{
            text: "确定", icon: "icon-save", handler: function () {
                var row = $("#tbList").datagrid("getSelected");
                var txtCopyXuhao = $("#txtCopyXuhao").val();
                // $.extend(row, { Xuhao: txtCopyXuhao, TaskId: Bom.settings.TaskId });
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=CopyOrgData", data: { Id: row.ID, Xuhao: txtCopyXuhao, TaskId: Bom.settings.TaskId, txtBeforeMap1: $("#txtBeforeMap1").val(), txtAfterMap1: $("#txtAfterMap1").val(), txtBeforeMap2: $("#txtBeforeMap2").val(), txtAfterMap2: $("#txtAfterMap2").val() }, success: function (data) {
                        var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                        $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                        $("#tbList").datagrid("unselectAll");
                        com.message(data.state, data.msg, function () {
                            $("#divCopyData").dialog("close");
                        });

                    }
                });
            }
        }, { text: "取消", handler: function () { $("#divCopyData").dialog("close"); } }],
        onClose: function () {
            $("#txtCopyXuhao").val(""),
            $("#txtBeforeMap1").val(""),
            $("#txtAfterMap1").val(""),
            $("#txtBeforeMap2").val(""),
            $("#txtAfterMap2").val("")
        }
    });
    $("#divCopyData").dialog("close");

    $('#divAddEquipSub').dialog({
        title: '添加设备子项名称',
        width: 300,
        height: 100,
        cache: false,
        modal: true,
        buttons: [{
            text: '保存',
            handler: function () {
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=AddEquip",
                    data: { Ids: Bom.settings.Ids, equipCode: $("#EquipSub").combobox("getValue"), equipName: $("#EquipSub").combobox("getText") },
                    success: function (data) {
                        com.message(data.state, data.msg);
                        $("#divAddEquipSub").dialog("close");
                        $("#tbList").datagrid("clearSelections");
                        $("#tbList").datagrid("reload");
                    }
                })

            }
        }, {
            text: '关闭',
            handler: function () {
                $('#divAddEquipSub').dialog('close');
            }
        }],
    });

    $('#divAddEquipSub').dialog("close");
}

//主数据查询
Bom.Search = function () {
    var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
    $.extend(o, com.serializeSearchArray("form1"));
    $.extend(o, com.getHighSearchList());
    $("#tbList").datagrid("load", o);
    // $("#tbList").datagrid("unselectAll");
    $("#divSearchShow").toggle();
    $("#tbList").datagrid("unselectAll");
}

Bom.Reset = function () {
    Bom.settings.MPState = "";
    Bom.settings.MPType = "";
    $("#lblMPType").html("");
    $("#form1").form("reset");
    $("#highSearchForm").form("reset");
    var para = com.serializeSearchArray("form1");
    $("#tbList").datagrid("load", para);
    $("#tbList").datagrid("unselectAll");
}


//查询面板显示隐藏
Bom.SearchShow = function () {

    $("#divSearchShow").toggle();
}


Bom.OpenEditWin = function () {

    $("#divOperate").dialog("open");
}

//变更零部件
Bom.AlterOrg = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length != 1) {
        com.message("information", "请选择一行！");
        return;
    } else {
        if (rows[0].AlterState != "1") {
            com.message("information", "你选择的零部件不能变更！");
            return;
        } else {
            if (rows[0].MpReviewState != "0" || rows[0].OsReviewState != "0" || rows[0].MkReviewState != "0" || rows[0].ZkAssState == "1" || rows[0].FfAssState == "1" || rows[0].MapAssState == "1" ) {
                com.message("information", "请注意物料状态！");
                return;
            }
            com.message("confirm", "您确定变更吗？", function (r) {
                if (r) {
                    com.ajax({
                        url: "/Logic/TM/OrgDataAjax.aspx?method=AlterData", data: { ID: rows[0].ID }, success: function (data) {
                            com.message(data.state, data.msg);
                            $("#tbList").datagrid("reload");
                        }
                    })
                }
            })
        }
    }
}
//标记为不变更
Bom.NoAlter = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length != 1) {
        com.message("information", "请选择一行！");
        return;
    } else {
        if (rows[0].AlterState != "1") {
            com.message("information", "你选择的零部件无法进行此操作！");
            return;
        } else {
            com.message("confirm", "您确定标记为不变更吗？请注意：标记为不变更将无法修改", function (r) {
                if (r) {
                    com.ajax({
                        url: "/Logic/TM/OrgDataAjax.aspx?method=MarkAsNoAlter", data: { ID: rows[0].ID }, success: function (data) {
                            com.message(data.state, data.msg);
                            $("#tbList").datagrid("reload");
                        }
                    })
                }
            })
        }
    }
}
//高级查询 
Bom.HighSearch = function () {

    $("#divHighSearch").dialog("open");
}

//新增
Bom.AddOrgData = function () {

    com.message("confirm", "您确定新增数据吗？请注意：该操作可能会出现未保存的数据", function (r) {
        if (r) {
            top.wrapper.addTab("新增原始数据", "/UI/TM/OrgDetailEdit.aspx?action=add&TaskId=" + Bom.settings.TaskId);
        }
    })
}
//转成装箱单
Bom.ExchangeBox = function () {
    com.ajax({
        url: "/Logic/TM/OrgDataAjax.aspx?method=ConvertToBox", data: { TaskId: Bom.settings.TaskId }, success: function (data) {
            com.message(data.state, data.msg)
        }
    });
}
//编辑
Bom.EditOrgData = function () {
    Bom.settings.Action = "edit";
    //  $("#XuhaoModel").combobox("setValue", "1");
    var rows = $("#tbList").datagrid("getSelections");
    var orgIds = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].MpReviewState != "0" || rows[i].OsReviewState != "0" || rows[i].MkReviewState != "0" || rows[i].ZkAssState == "1" || rows[i].FfAssState == "1" || rows[i].MapAssState == "1") {
                com.message("information", "该条记录正在审核中，无法编辑");
                return;
            }
            else {
                orgIds += rows[i].ID + ",";
            }
        }
        top.wrapper.addTab("原始数据编辑", "/UI/TM/OrgDetailEdit.aspx?action=edit&TaskId=" + Bom.settings.TaskId + "&orgIds=" + orgIds.trim(','));
    }
    else {
        com.message("information", "请选中一行");
    }
}


//只编辑明细
Bom.EditMsOrgData = function () {
    Bom.settings.Action = "edit";
    //  $("#XuhaoModel").combobox("setValue", "1");
    var rows = $("#tbList").datagrid("getSelections");
    var orgIds = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            orgIds += rows[i].ID + ",";

        }
        top.wrapper.addTab("原始数据明细编辑", "/UI/TM/OrgDetailEdit.aspx?action=editMs&TaskId=" + Bom.settings.TaskId + "&orgIds=" + orgIds.trim(','));
    }
    else {
        com.message("information", "请选中一行");
    }
}

Bom.DeleteOrg = function () {
    var rows = $("#tbList").datagrid("getSelections");
    var Ids = "";
    var Xuhao = "";
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            Xuhao += rows[i].Xuhao + ","
        }

        for (var i = 0; i < rows.length; i++) {
            Ids += rows[i].ID + ","
        }
        Xuhao.trim(',');
        com.message("confirm", "您确定要删除序号为【" + Xuhao + "】的记录吗？", function (r) {
            if (r) {
                //  alert("a");
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=DeleteOrg", data: { TaskId: Bom.settings.TaskId, Ids: Ids }, success: function (data) {
                        com.message(data.state, data.msg, function () {
                            var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                            $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                            $("#tbList").datagrid("unselectAll");

                        })
                    }
                });
            }

        })
    }
    else {
        com.message("information", "请选中一行");
    }
}




//导入数据
Bom.ExportHistory = function () {

    var taskId = $("#TaskId").val();
    top.wrapper.addTab("数据导入", "/UI/TM/OrgDataExport.aspx?TaskId=" + taskId);


}


//复制数据
Bom.CopyData = function () {
    var row = $("#tbList").datagrid("getSelected");
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length == 1) {
        $("#divCopyData").dialog("open");
    }
    else {
        com.message("information", "请选择一条数据");
    }
}


//批量复制数据
Bom.BatchCopyData = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 1) {
        var Ids = "";
        for (var i = 0; i < rows.length; i++) {
            Ids += rows[i].ID + ",";
        }
        top.wrapper.addTab("批量复制", "/UI/TM/OrgDetailEdit.aspx?action=batch&TaskId=" + Bom.settings.TaskId + "&Ids=" + Ids);
    }
    else {
        com.message("information", "请选择至少两条数据");
    }
}




Bom.EditCopySwitch = function () {
    if (Bom.settings.CopySwitch == "0") {
        Bom.settings.CopySwitch = "1";
        $("#CopySwitch").html("关");
    }
    else {
        Bom.settings.CopySwitch = "0";
        $("#CopySwitch").html("开");
    }
}


//增加前缀图号
Bom.AddFrontMap = function () {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        $("#divMap").dialog("open");
    } else {
        com.message("information", "请选择至少一条数据");
    }
}



//清空前缀图号
Bom.DeleteFrontMap = function () {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=DeleteFrontMap", data: { orgData: JSON.stringify(rows) }, success: function (data) {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType };
                $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                $("#tbList").datagrid("unselectAll");
                com.message(data.state, data.msg);
            }
        });
    } else {
        com.message("information", "请选择至少一条数据");
    }
}


//列窗口打开
Bom.ColumnShow = function () {
    $("#divColumn").dialog("open");

    //加载原始数据列表
    $("#tbColumn").datagrid({
        url: "/Logic/TM/OrgDataAjax.aspx?method=GetBomColumns",
        loadMsg: '数据加载中请稍后……',
        fitColumns: true,
        rownumbers: true,
        idField: "FieldId",
        singleSelect: true,
        striped: true,
        columns: [[
             { field: 'TableEngName', title: '表格 ', align: "center" },
             { field: 'TableName', title: '表名称 ', align: "center" },
             { field: 'Field', title: '字段 ', align: "center", width: 80 },
             { field: 'Title', title: '标题 ', align: "center" },
   {
       field: 'Length', title: '列宽度 ', align: "center", editor: {
           type: "numberbox",
           options: {
               required: true
           }
       }
   },
    {
        field: 'OrderField', title: '排序 ', align: "center", editor: {
            type: "validatebox",
            options: {

            }
        }
    },
             {
                 field: 'IsHidden', title: '是否显示 ', align: "center", editor: {
                     type: "combobox",
                     options: {
                         data: StaticCombo.ColumnShown,
                         valueField: 'value',
                         textField: 'text',
                         panelHeight: 'auto'

                     }
                 }, formatter: function (value, row, index) {
                     return com.getArrayText(StaticCombo.ColumnShown, value);
                 }
             },
        ]], onDblClickRow: function (rowIndex, rowData) {
            if (Bom.settings.editRow == undefined) {
                $("#tbColumn").datagrid("beginEdit", rowIndex);
                Bom.settings.editRow = rowIndex;
            }
            else {
                $('#tbColumn').datagrid('endEdit', Bom.settings.editRow);
            }
        }, onAfterEdit: function (rowIndex, rowData, changes) {
            com.ajax({
                url: "/Logic/TM/OrgDataAjax.aspx?method=SaveColumnShown",
                data: rowData,
                success: function (data) {
                    com.message(data.state, data.msg, function () { $("#tbColumn").datagrid("reload"); });
                    $("#tbList").datagrid("unselectAll");
                }
            });

            Bom.settings.editRow = undefined;
        }
    });

}

//下推图纸分工
Bom.MapAssPushDown = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].MapAssState == "2" || rows[i].MapAssState == "1") {
                com.message("information", "序号为【" + rows[i].Xuhao + "】已经下推制作任务单，操作被终止！");
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=MapAssPushDown", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows) }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

Bom.ZkMapAssPushDown = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].ZkAssState == "2" || rows[i].ZkAssState == "1") {
                com.message("information", "序号为【" + rows[i].Xuhao + "】已经下推制孔任务单，操作被终止！");
                return;
            }
            if (rows[i].Kong == "" || rows[i].Kong == null) {
                com.message("information", "序号为【" + rows[i].Xuhao + "】不含有孔，操作被终止！");
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=ZkMapAssPushDown", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows) }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

Bom.FfMapAssPushDown = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].FfAssState == "2" || rows[i].FfAssState == "1") {
                com.message("information", "序号为【" + rows[i].Xuhao + "】已经下推防腐任务单，操作被终止！");
                return;
            }
            if (rows[i].ComponentIDNum == "" || rows[i].ComponentIDNum == null) {
                com.message("information", "序号为【" + rows[i].Xuhao + "】不是构件，操作被终止！");
                return;
            }
            if (rows[i].PackNum == "" || rows[i].PackNum == null || rows[i].BoxNum == "" || rows[i].BoxNum == null) {
                com.message("information", "序号为【" + rows[i].Xuhao + "】的零部件未添加包号或者箱号，操作被终止！");
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=FfMapAssPushDown", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows) }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

//同布分工数据
Bom.UploadAssignData = function () {

    com.ajax({
        data: { TaskId: Bom.settings.TaskId },
        url: "/Logic/TM/OrgDataAjax.aspx?method=UploadAssignData",
        success: function (data) {
            com.message(data.state, data.msg);
            $("#tbList").datagrid("reload");
        }
    });
}


//标记为
Bom.MarkAs = function (type, state) {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        for (var i = 0; i < rows.length; i++) {
            if ((rows[i].MpReviewState == "1" && type == "MpState") || (rows[i].MsReviewState == "1" && type == "MsState") || (rows[i].OsReviewState == "1" && type == "OsState") || ((rows[i].FfReviewState == "1" && type == "FfState")) || ((rows[i].MkReviewState == "1" && type == "MkState"))) {
                com.message("information", "勾选的记录正在审核，无法被标记！")
                return;
            }
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=MarkAsState", data: { TaskId: Bom.settings.TaskId, OrgData: JSON.stringify(rows), type: type, state: state, CopySwitch: Bom.settings.CopySwitch }, success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
                $("#tbList").datagrid("unselectAll");
            }
        });
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

Bom.ExportBlankPlan = function () {

    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0) {
        var Ids = "";
        for (var i = 0; i < rows.length; i++) {
            Ids += rows[i].ID + ",";
        }
        top.wrapper.addTab("下料计划Excel", "/ExportModel/OrgBlankExport.aspx?taskId=" + Bom.settings.TaskId + "&Ids=" + Ids);
    }
    else {
        com.message("information", "请至少选择一条数据");
    }
}

Bom.XlPlan = function (MaType) {
    com.ajax({
        url: "/Logic/TM/OrgDataAjax.aspx?method=GetXlData", data: { taskId: Bom.settings.TaskId, MaType: MaType }, success: function (data) {
            if (data.length == 0) {
                com.message("error", "没有需要下料的材料！");

            } else {
                com.ajax({
                    url: "/Logic/TM/OrgDataAjax.aspx?method=DownXl", data: { taskId: Bom.settings.TaskId, MaType: MaType }, success: function (data) {
                        com.message(data.state, data.msg);
                        if (data.maType == "ban") {
                            top.wrapper.addTab("板材下料审批", data.url);
                        } else {
                            top.wrapper.addTab("型材下料审批", data.url);
                        }

                    }
                })
            }

        }
    });
}

Bom.SortByMs = function () {
    $("#tbList").datagrid("clearSelections");
    var o = { Sort: "MxXuhao" };
    var param = com.serializeSearchArray("form1");
    $("#tbList").datagrid("load", $.extend(param, o));

    $("#tbList").datagrid("unselectAll");
}



Bom.MPSearch = function (MPType, MPState, SubmitType) {
    $("#tbList").datagrid("clearSelections");
    Bom.settings.MPState = MPState;
    Bom.settings.MPType = MPType;
    Bom.settings.SubmitType = SubmitType;
    $("#lblMPType").html(MPType);
    var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType, TaskId: Bom.settings.TaskId };
    //$("#form1").form("reset");
    var param = com.serializeSearchArray("form1");
    $("#tbList").datagrid("load", $.extend(param, o));
    $("#tbList").datagrid("unselectAll");
}


Bom.SubmitChange = function (type, level) {
    var rows = $("#tbList").datagrid("getSelections");
    if (Bom.settings.MPState == "" || Bom.settings.MPType == "") {
        com.message("information", "请先选择提交类别！");
        return;
    }
    var MPType = Bom.settings.MPType;
    var MPState = Bom.settings.MPState;
    var Ids = "";
    if (MPType == "制作明细") {

        if (MPState == "All") {
            var newRows = $("#tbList").datagrid("getRows");
            if (newRows.length == 0) {
                com.message("error", "没有可提交的数据！");
                return;
            }

        }
    }
    else {

        if (rows.length > 0) {
            for (var i = 0; i < rows.length; i++) {
                var item = rows[i];
                if (MPType == "定尺板" || MPType == "非定尺板" || MPType == "型材" || MPType == "标(发运)" || MPType == "标(组装)") {

                    if (item.MaterialCode != "") {
                        if (MPState == "Normal") {
                            if (item.MpState != "0") {
                                com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                                return;
                            }
                        }
                        else if (MPState == "Change") {
                            if (item.MpState != "2" && item.MpState != "3") {
                                com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                                return;
                            }
                            if (item.MpReviewState != "0") {
                                com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                                return;
                            }
                        }
                    }
                    else {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料编码为空，提交被终止！");
                        return;
                    }
                }
                else if (MPType == "油漆计划") {
                    if (MPState == "Normal") {
                        if (item.MpState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                        if (item.BottomPaint == "" && item.MiddlePaint == "" && item.SurfacePaint == "") {
                            com.message("error", "序号为【" + item.Xuhao + "】的油漆种类不能为空)");
                            return;
                        }
                        if (item.PaintProgram == "" || item.PaintProgram == "X+X+X") {
                            com.message("error", "序号为【" + item.Xuhao + "】的喷漆方案不能为空)");
                            return;
                        }
                        if (item.SingleOrDouble == "") {

                            com.message("error", "序号为【" + item.Xuhao + "】的是否单面喷漆不能为空)");
                            return;
                        }
                    }
                    else if (MPState == "Change") {
                        if (item.MpState != "2" && item.MpState != "3") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                            return;
                        }
                        if (item.MpReviewState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                            return;
                        }
                    }
                }
                else if (MPType == "制作报量") {
                    console.log(item.MsState);
                    console.log(typeof item.MsState);
                    if (MPState == "Normal") {
                        if (item.MsState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                        if (item.ClassId == 0 || typeof (item.ClassId) == undefined || item.ClassId == null) {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料未找到班组分工数据，提交被终止！");
                            return;
                        }
                        //if (item.PackNum == "" || typeof (item.PackNum) == undefined) {
                        // com.message("error", "序号为【" + item.Xuhao + "】的物料没有包号，提交被终止！");
                        //return;
                        //}
                        if (item.ComponentIDNum == "" || item.ComponentIDNum == null || typeof (item.ComponentIDNum) == undefined) {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料不是构件行，提交被终止！");
                            return;
                        }
                        if (item.EquipSubName == "" || item.EquipSubName == null || typeof (item.EquipSubName) == undefined) {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料设备子项行为空，提交被终止！");
                            return;
                        }
                    }
                    else if (MPState == "Change") {
                        if (item.MsState != "2" && item.MsState != "3") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                            return;
                        }

                    }

                }
                else if (MPType == "成交" || MPType == "协A" || MPType == "协B") {
                    if (item.MaterialCode != "") {
                        if (MPState == "Normal") {
                            if (item.OsState != "0") {
                                com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                                return;
                            }
                        }
                        else if (MPState == "Change") {
                            if (item.OsState != "2" && item.OsState != "3") {
                                com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"变更或变更删除\"，提交被终止！");
                                return;
                            }

                            if (item.OsReviewState != "0") {
                                com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                                return;
                            }

                        }
                    }
                    else {
                        com.message("error", "序号为【" + item.Xuhao + "】的物料编码为空，提交被终止！");
                        return;
                    }
                }
                else if (MPType == "防腐报量") {

                    if (MPState == "Normal") {
                        if (item.FfState !== "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                        if (item.FangFuId == "0" || item.FangFuName == "" || item.FangFuName == null || typeof (item.FangFuId) == undefined) {
                            com.message("error", "序号为【" + item.Xuhao + "】的防腐班组为空，提交被终止！");
                            return;
                        }
                    }
                }
                else if (MPType == "制孔报量") {

                    if (MPState == "Normal") {
                        if (item.ZkState !== "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                        if (item.ZkClassId == "0" || item.ZkClassName == "" || item.ZkClassName == null || typeof (item.ZkClassId) == undefined) {
                            com.message("error", "序号为【" + item.Xuhao + "】的制孔班组为空，提交被终止！");
                            return;
                        }
                    }
                }

                else if (MPType == "材料计划") {

                    if (MPState == "Normal") {

                        if (item.MpState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                    }
                    if (MPState == "Change") {
                        if (item.MpReviewState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                            return;
                        }
                    }
                }
                else if (MPType = "外协计划") {

                    if (MPState == "Normal") {
                        if (item.OsState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的物料状态应为\"未提交\"，提交被终止！");
                            return;
                        }
                    }
                    if (MPState == "Change") {
                        if (item.OsReviewState != "0") {
                            com.message("error", "序号为【" + item.Xuhao + "】的记录正在审核中，无法再次提交");
                            return;
                        }
                    }
                }
                Ids = Ids + item.ID + ",";
            }
        }
        else {
            com.message("information", "请至少选择一条数据");
            return;
        }
    }


    com.ajax({
        url: "/Logic/TM/OrgDataAjax.aspx?method=SubmitOrgData",
        data: { MPState: Bom.settings.MPState, OrgData: Ids, MPType: Bom.settings.MPType, TaskCode: Bom.settings.TaskCode, TaskId: Bom.settings.TaskId },
        success: function (data) {
            if (data.state == "error") {
                com.message("error", data.msg);
            }
            else {
                $("#tbList").datagrid("unselectAll");
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                if (data.returnValue && data.returnValue != null) {
                    top.wrapper.addTab(data.returnValue.split('|')[1], data.url);
                }



            }

        }
    });
}



Bom.CalCulateWeight = function () {
    com.ajax({
        url: "/Logic/TM/OrgDataAjax.aspx?method=CalCulateWeight", data: { taskId: Bom.settings.TaskId }, success: function (data) {
            com.message(data.state, data.msg, function () {
                var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
                $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
                $("#tbList").datagrid("unselectAll");
                $("#lblTaskWeight").html(data.returnValue);
            })
        }
    });
}


Bom.CheckKuWeight = function () {
    top.wrapper.addTab("核对库重量", "/UI/TM/OrgDataCheckKuWeight.aspx?TaskId=" + Bom.settings.TaskId);
    //var rows = $("#tbList").datagrid("getSelections");
    //if (rows.length != 0) {
    //    com.ajax({
    //        url: "/Logic/TM/OrgDataAjax.aspx?method=CheckKuWeight", data: { taskId: Bom.settings.TaskId, data: JSON.stringify(rows) }, success: function (data) {
    //            com.message(data.state, data.msg)
    //        }
    //    });
    //}
    //else {
    //    com.message("information", "请至少选择一条数据");
    //}
}

Bom.ExportExcel = function () {
    var taskId = $("#TaskId").val();
    //alert(taskId);
    //var o = { MPState: Bom.settings.MPState, MPType: Bom.settings.MPType, SubmitType: Bom.settings.SubmitType };
    var high = com.getHighSearchList();
    var highSerach = high.highSearchData;
    top.wrapper.addTab("导出Excel", "/ExportModel/OrgDataExport.aspx?searchData=" + com.serializeSearchArray1("form1") + "&highsearchData=" + highSerach + "&MPState=" + Bom.settings.MPState + "&MPType=" + Bom.settings.MPType + "&SubmitType=" + Bom.settings.SubmitType) + "&TaskId=" + taskId;
}


Bom.AdjustMsDetail = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length > 0 && rows.length < 2) {
        var row = $("#tbList").datagrid("getSelected");
        top.wrapper.addTab("明细调整模式", "/UI/TM/OrgMsAdjustNew.aspx?TaskId=" + Bom.settings.TaskId + "&OrgId=" + row.ID + "&Xuhao=" + row.Xuhao);
    }
    else {
        com.message("information", "请选择一行")
    }

}

Bom.OrgTreeDetail = function () {
    var rows = $("#tbList").datagrid("getSelections");

    if (rows.length == 0) {
        top.wrapper.addTab("层级关系模式", "/UI/TM/OrgMsAdjust.aspx?TaskId=" + Bom.settings.TaskId + "&Xuhao=*");
    }
    else if (rows.length > 0 && rows.length < 2) {
        var row = $("#tbList").datagrid("getSelected");
        top.wrapper.addTab("层级关系模式", "/UI/TM/OrgMsAdjust.aspx?TaskId=" + Bom.settings.TaskId + "&OrgId=" + row.ID + "&Xuhao=" + row.Xuhao);

    }
    else {
        com.message("information", "请选择一行")
    }


}
Bom.ViewGouJian = function () {
    var o = { GouJianState: "yes", taskId: com.get.Id };
    $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
}
Bom.ViewKong = function () {
    var o = { KongState: "yes", taskId: com.get.Id };
    $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
}
Bom.ViewLuoShuan = function () {
    var o = { LuoShuanState: "yes", taskId: com.get.Id };
    $("#tbList").datagrid("load", $.extend(com.serializeSearchArray("form1"), o));
}



Bom.AddTuZhuang = function () {
    var row = $('#tbList').datagrid('getSelected');
    var rows = $('#tbList').datagrid('getSelections')
    var flag = true;
    if (row) {
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].ComponentIDNum == '' || rows[i].MaState == '标' || rows[i].MaterialName == '钢格板' || rows[i].MaterialName == 'C型钢' || rows[i].MaterialName == '彩板') {
                flag = false;
                break;
            }
        }
        if (flag) {
            for (var i = 0; i < rows.length; i++) {
                Bom.settings.Ids += rows[i].ID + ",";
            }
            $('#divAddTuZhuang').dialog('open');

        } else {
            com.message('information', '所选择的数据中存在不能添加涂装材料的数据，请重新选择！！！');
        }
    } else {
        com.message('information', '请至少选中一行!')
    }

}
Bom.SelectPain = function (record) {
    var tr = $(this).closest("tr");
    var value = record.value;
    tr.find(".ZhongLei").combogrid({
        panelWidth: 500,
        mode: "remote",
        url: "/Logic/TM/OrgDataAjax.aspx?method=GetMaterial",
        queryParams: { value: value },
        idField: 'Material',
        textField: 'Material',
        pagination: true,//是否分页  
        rownumbers: true,//序号  
        collapsible: false,//是否可折叠的  
        fit: true,//自动大小  
        pageSize: 10,//每页显示的记录条数，默认为10  
        pageList: [10, 20, 50],//可以设置每页记录条数的列表  

        columns: [[
            { field: 'Material', title: '编码', width: 120 },
            { field: 'Name', title: '名称', width: 170 },
            { field: 'Guige', title: '规格', width: 170 },
        ]]

    })
}
Bom.AddEquipSub = function () {
    var rowData = $("#tbList").datagrid("getSelections");
    if (rowData.length != 0) {

        for (var i = 0; i < rowData.length; i++) {
            Bom.settings.Ids += rowData[i].ID + ",";
            if (rowData[i].ComponentIDNum == null || rowData[i].ComponentIDNum == "") {
                com.message("information", "序号为【" + rowData[i].Xuhao + "】的选中行不是构件，添加被终止！");
                return;
            }

        }
        $('#divAddEquipSub').dialog("open");
    }
    else {
        com.message("information", "请至少选中一行！")
    }


}

Bom.StateColumnHide = function () {


    $("#tbList").datagrid("hideColumn", "MpState");
    $("#tbList").datagrid("hideColumn", "MsState");
    $("#tbList").datagrid("hideColumn", "FfState");
    $("#tbList").datagrid("hideColumn", "OsState");
    $("#tbList").datagrid("hideColumn", "MapAssState");
    $("#tbList").datagrid("hideColumn", "MkState");
    $("#tbList").datagrid("hideColumn", "IsReplace");
    $("#tbList").datagrid("hideColumn", "ZkState");

    $("#tbList").datagrid("reload");


}

Bom.StateColumnShow = function () {
    $("#tbList").datagrid("showColumn", "MpState");
    $("#tbList").datagrid("showColumn", "MsState");
    $("#tbList").datagrid("showColumn", "FfState");
    $("#tbList").datagrid("showColumn", "OsState");
    $("#tbList").datagrid("showColumn", "MapAssState");
    $("#tbList").datagrid("showColumn", "MkState");
    $("#tbList").datagrid("showColumn", "IsReplace");
    $("#tbList").datagrid("showColumn", "ZkState");
    $("#tbList").datagrid("reload");
}

Bom.SinglePaint = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length != 0) {
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids += rows[i].ID + ",";
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=SetPaint",
            data: { taskId: Bom.settings.TaskId, Ids: ids, type: "single" },
            success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
            }

        });
    }
    else {
        com.message("information", "请至少选中一行！")
    }
}
Bom.DoublePaint = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length != 0) {
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids += rows[i].ID + ",";
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=SetPaint",
            data: { taskId: Bom.settings.TaskId, Ids: ids, type: "double" },
            success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
            }

        });
    }
    else {
        com.message("information", "请至少选中一行！")
    }
}
Bom.NonPaint = function () {
    var rows = $("#tbList").datagrid("getSelections");
    if (rows.length != 0) {
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids += rows[i].ID + ",";
        }
        com.ajax({
            url: "/Logic/TM/OrgDataAjax.aspx?method=SetPaint",
            data: { taskId: Bom.settings.TaskId, Ids: ids, type: "non" },
            success: function (data) {
                com.message(data.state, data.msg);
                $("#tbList").datagrid("reload");
            }

        });
    }
    else {
        com.message("information", "请至少选中一行！")
    }
}


Bom.AdjustXuhao = function () {
    $('#divAdjustXuhao').dialog("open");
}



$(Bom.init);

